<template>
    <!-- 
    <b-modal ref="my-modal" hide-footer title="Using Component Methods">
     <div class="d-block text-center">
       <h3>Hello From My Modal!</h3>
     </div>
     <b-button class="mt-3" variant="outline-danger" block @click="hideModal">Close Me</b-button>
     <b-button class="mt-2" variant="outline-warning" block @click="toggleModal">Toggle Me</b-button>
   </b-modal> 
    -->
    <!--
        body-class="modalStyle" 表示样式
        size="lg" 表示模态窗口大小 xl,lg,sm,full
        hide-footer 表示隐藏底部按钮
        hide-header 表示隐藏头部内容
        no-close-on-backdrop 表示鼠标点击背景不可关闭
        hide-header-close 表示隐藏头部关闭按钮
        centered 居中
        ok-title=“确定” 
        cancel-title=取消
        @ok="handleOk" 
        @cancel="handleCancel"
        scrollable 滚动条
        hide-backdrop 隐藏背景
        wrapClassName="ant-modal-cust-warp" 
        style="top:5%;height: 85%;overflow-y: hidden" 样式
    -->
    <b-modal ref="my-modal" title="租户" scrollable no-close-on-backdrop> 
        <div class="card card-custom gutter-b example example-compact" id="tableAccountTenantBody">               
            <!--分页组件-->
            <el-table style="width: 100%"
                stripe border @selection-change="handleSelectionChange" highlight-current-row :data="tenantDataList" >
              <!-- 复选框 -->
              <el-table-column type="selection" width="40"></el-table-column>
              <el-table-column label="序号" width="80">
                  <template slot-scope="scope">
                  {{scope.$index+1}} 
                  </template>
              </el-table-column>
              <el-table-column align="left" prop="name" label="租户"></el-table-column>       
              <el-table-column align="left" prop="code" label="编码"></el-table-column>       
              <el-table-column align="left" prop="sysModeName" label="隶属系统"></el-table-column> 
              <el-table-column align="center" label="操作" fixed="left" min-width="60">
                <template slot-scope="scope">
                  <a href="javascript:;" @click="deleteAccountTenant(scope.row)" class="btn btn-sm btn-clean btn-icon" title="解除绑定">	                            
                    <span class="svg-icon svg-icon-primary svg-icon-2x">	                                
                        <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24px" height="24px" viewBox="0 0 24 24" version="1.1">	                                    
                            <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">	                                       
                                <rect x="0" y="0" width="24" height="24"></rect>	                                        
                                <path d="M6,8 L6,20.5 C6,21.3284271 6.67157288,22 7.5,22 L16.5,22 C17.3284271,22 18,21.3284271 18,20.5 L18,8 L6,8 Z" 
                                fill="#000000" fill-rule="nonzero"></path>	                                        
                                <path d="M14,4.5 L14,4 C14,3.44771525 13.5522847,3 13,3 L11,3 C10.4477153,3 10,3.44771525 10,
                                    4 L10,4.5 L5.5,4.5 C5.22385763,4.5 5,4.72385763 5,5 L5,5.5 C5,5.77614237 5.22385763,6 5.5,6 L18.5,
                                    6 C18.7761424,6 19,5.77614237 19,5.5 L19,5 C19,4.72385763 18.7761424,4.5 18.5,4.5 L14,4.5 Z" fill="#000000" opacity="0.3">
                                </path>	                                    
                            </g>	                                
                        </svg>	                            
                    </span>							
                </a>
                </template>
              </el-table-column>      
            </el-table>
        </div>
        <template slot="modal-footer">
            <!--自定义按钮-->            
            <button type="button" class="btn btn-light-danger font-weight-bold mr-2" block @click="hideModal">
                <i class="icon-xl fa fa-times"></i>取消
            </button> 
            <b-button  @click="showOauthAccountTenant" > 
              <span><i class=" fas fa-user-cog"></i><span>选择租户</span></span>
            </b-button>
        </template>
        
        <AccountTenantSelect ref="accountTenantSelectRef" @change="initList"></AccountTenantSelect>
     </b-modal>
</template>  
<script>
  import Swal from "sweetalert2";
  import apiUtil from "@/core/util/apiUtil.js"; 
  import AccountTenantSelect from "@/view/oauth/oauth-account/account-tenant-select.vue";
  import { handleNotify,handleAlert,handleConfirm,showWating,closeWating} from "@/core/util/jehcUtil.js";
  export default {
    data(){
      return{
        accountTypeId:'',
        tenantDataList:[],
        oauthAccountTenantForm:{
            oauthAccountTenants: [

            ],
            account:"",
        },        
        sels: [], //当前选框选中的值
      }
    },
    components: {
      AccountTenantSelect,
    },
    mounted() {

    },
    methods:{
      showModal(account_type_id,account) {     
        this.accountTypeId = account_type_id; 
        this.account = account;
        this.$refs['my-modal'].show();
        this.initList(account_type_id);   // 按当前的页号和每页的数据量进行查询
      },
      hideModal() {
        this.$refs['my-modal'].hide()
      },
      toggleModal() {
        // 当模态已隐藏时，我们传递要返回焦点的按钮的ID
        this.$refs['my-modal'].toggle('#toggle-btn')
      },
      initList(){
        showWating({renderBody:"tableAccountTenantBody"});  
        apiUtil.get(process.env.VUE_APP_OAUTH_API+"/oauthAccountTenant/list?account="+this.account).then(({ data }) => {
          this.tenantDataList = data.data;//给结果集赋值
        });
      },      
      handleSelectionChange(sels) {//获取选中的值
        this.sels = sels;
      },   
      showOauthAccountTenant(){
        this.$refs.accountTenantSelectRef.showModal(this.accountTypeId,this.account);
      },
      deleteAccountTenant(row){        
        this.$confirm("确认删除租户【"+row.name+"】吗?", "提示", {type: "warning",}).then(() => {
          apiUtil.delete(process.env.VUE_APP_OAUTH_API+"/oauthAccountTenant/delete",{id:row.id}).then(data=>{
            if(data.data.success){
              handleAlert("删除成功", "success", 3);
              this.initList();
            }else {
              handleAlert("删除失败", "error", 3);
            }
          });
        }).catch(()=>{});//注意这里，这里是重点！！！; 
      },
    }
  };
</script>